#ifndef UTIL_H
#define UTIL_H

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif

#ifndef trim
#define trim(x, a, b) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x)))
#endif

void show_buffer(unsigned char *buffer, unsigned char size);
void buffer_left_shift(unsigned char *pbuffer, unsigned char length, unsigned char offset);
void buffer_right_shift(unsigned char *pbuffer, unsigned char length, unsigned char offset);

unsigned short crc16(unsigned char *pbuffer, unsigned char length);

void die();

unsigned char hex_to_binary(unsigned char ch);
void binary_to_hex(unsigned char dat);

#endif